﻿@model ManufacturerListModel
@using Telerik.Web.Mvc.UI
@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    //page title
    ViewBag.Title = T("Admin.Catalog.Manufacturers").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
        @T("Admin.Catalog.Manufacturers")
    </div>
    <div class="options">
        <a href="@Url.Action("Create")" class="t-button">@T("Admin.Common.AddNew")</a>
        <a href="@Url.Action("ExportXml")" class="t-button">@T("Admin.Common.ExportToXml")</a>
    </div>
</div>
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.SearchManufacturerName):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => Model.SearchManufacturerName)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="btnSearch" class="t-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>
<p></p>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<ManufacturerModel>()
                    .Name("manufacturers-grid")
                    .ClientEvents(events => events
                        .OnDataBinding("onDataBinding"))
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name).Width(300);
                        columns.Bound(x => x.Published)
                            .Template(
                                @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.Published.ToString().ToLowerInvariant() + ".gif")" />
                            )
                            .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= Published #>.gif' />")
                            .Centered()
                            .Width(100);
                        columns.Bound(x => x.DisplayOrder)
                            .Width(100)
                            .Centered();
                        columns.Bound(x => x.Id)
                            .Width(50)
                            .Centered()
                            .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }))
                            .ClientTemplate("<a href=\"Edit/<#= Id #>\">" + T("Admin.Common.Edit").Text + "</a>")
                            .Title(T("Admin.Common.Edit").Text);
                    })
                    .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding => dataBinding.Ajax().Select("List", "Manufacturer"))
                    .EnableCustomBinding(true))
        </td>
    </tr>
</table>
<script type="text/javascript">
    $(document).ready(function () {
        //search button
        $('#btnSearch').click(function () {
            //search
            var grid = $('#manufacturers-grid').data('tGrid');
            grid.currentPage = 1; //new search. Set page size to 1
            grid.ajaxRequest();
            return false;
        });

        $("#@Html.FieldIdFor(model => model.SearchManufacturerName)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#btnSearch").click();
                return false;
            }
        });
    });

    function onDataBinding(e) {
        var searchModel = {
            SearchManufacturerName: $('#@Html.FieldIdFor(model => model.SearchManufacturerName)').val()
        };
        e.data = searchModel;
    }
</script>